<?php
/**
 * controller file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2020/05/30
 * Time: 09:05
 */

namespace Modules\Admin\Http\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Request;
use Modules\Admin\Service\AppService;

class AppController extends BaseController
{
    public function app_index(){
        try {
            $result = AppService::get_new_version_list();
            return view('admin::app.app_index',$result);
        } catch (\Exception $exception) {
            return ['state' => 1, 'msg' => $exception->getMessage()];
        }


    }

    /**
     * 添加页面
     */
    public function app_add()
    {
        $arr_data = [
          'arr_app_type'=>[
            '1'=>'安卓-用户端',
            '3'=>'安卓-商户端',
            '2'=>'苹果-用户端',
            '4'=>'苹果商户端',
          ],
          'arr_is_force'=>[
            '1'=>'是',
            '2'=>'否',
          ]
        ];
        return view('admin::app.app_add',$arr_data);
    }

    public function app_add_do(){
        try {
            $arr_input = Request::input();
            $result = AppService::add_one_version($arr_input);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 列表
     */
    public function index()
    {
        try {
            $result = AppService::get_new_version_list();
            return view('admin::app.index',$result);
        } catch (\Exception $exception) {
            return ['state' => 1, 'msg' => $exception->getMessage()];
        }
    }

    /**
     * 修改页面
     */
    public function edit()
    {
        $nId = Request::get('id', 0);
        $res = AppService::get_one((int)$nId);
        echo_error($res);

        return view('admin::app.edit', $res);
    }

    /**
     * 修改 操作
     */
    public function update()
    {
        $arr_input = Request::input();

        return AppService::edit_one($arr_input);
    }


    /**
     * 更改 XXX 状态
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function change_state()
    {
        $arr_input = Request::input();
        return AppService::change_one_state($arr_input);
    }

    /**
     * 删除 XXX
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function delete()
    {
        $n_id = (int)Request::get('id', 0);
        return AppService::delete_one($n_id);
    }
}